import { request, config } from 'utils'
import * as commonService from './common4Report'

const { api } = config
const { reportConfig, adrReport } = api

export async function query(params = {}) {
  params.apiBaseUrl = `${reportConfig}`;
  return commonService.commonQuery(params);
}

export async function detail(id) {
  const url = `${reportConfig}/detail/${id}`;
  return request({ url: url, method: 'get', data: {} })
}

export async function upload(path, params) {
  const url = `${reportConfig}/upload/${path}`;
  return request({ url: url, method: 'post', data: params })
}

export async function create(params) {
  const url = `${reportConfig}/create`;
  return request({ url: url, method: 'put', data: params })
}

export async function update(params) {
  const url = `${reportConfig}/update`;
  return request({ url: url, method: 'put', data: params })
}

export async function deleteBy(id, version) {
  const url = `${reportConfig}/delete/${id}/${version}`;
  return request({ url: url, method: 'post', data: {} })
}

export async function grant(id, params) {
  const url = `${reportConfig}/grant/${id}`;
  return request({ url: url, method: 'put', data: params })
}

export async function removeGrantBy(id, params) {
  const url = `${reportConfig}/removeGrant/${id}`;
  return request({ url: url, method: 'put', data: params })
}

export async function getGrantIdsBy(id) {
  const url = `${reportConfig}/getGrantIds/${id}`;
  return request({ url: url, method: 'put', data: {} })
}

export async function getGrantUserBy(id) {
  const url = `${adrReport}/adrReport/getGrantUser/${id}`;
  return request({ url: url, method: 'get', data: {} })
}
